package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxOrderItem;
import com.ruoyi.system.service.fx.IFxOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单项目Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/fx/order/item")
public class FxOrderItemController extends BaseController {
    @Autowired
    private IFxOrderItemService fxOrderItemService;

    /**
     * 查询订单项目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxOrderItem fxOrderItem) {
        List<FxOrderItem> list = fxOrderItemService.selecOrderItemList(fxOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单项目列表
     */
    @Log(title = "订单项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxOrderItem fxOrderItem) {
        List<FxOrderItem> list = fxOrderItemService.selecOrderItemList(fxOrderItem);
        ExcelUtil<FxOrderItem> util = new ExcelUtil<FxOrderItem>(FxOrderItem.class);
        util.exportExcel(response, list, "订单项目数据");
    }

    /**
     * 获取订单项目详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxOrderItemService.selectFxOrderItemById(id));
    }

    /**
     * 新增订单项目
     */
    @Log(title = "订单项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxOrderItem fxOrderItem) {
        return toAjax(fxOrderItemService.insertFxOrderItem(fxOrderItem));
    }

    /**
     * 修改订单项目
     */
    @Log(title = "订单项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxOrderItem fxOrderItem) {
        return toAjax(fxOrderItemService.updateFxOrderItem(fxOrderItem));
    }

    /**
     * 删除订单项目
     */
    @Log(title = "订单项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxOrderItemService.deleteFxOrderItemByIds(ids));
    }
}
